package web;

import data.Show;
import web.rssReader.DailyTvTorrentRssReader;
import web.xmlReader.TvRageXmlReader;

public class PopulateShow 
{

	private TvRageXmlReader tvrage;
	private DailyTvTorrentRssReader daily;
	
	public PopulateShow(String showName)
	{
		tvrage = new TvRageXmlReader(showName);
		//eztv = new EztvRssReader(showName);
		daily = new DailyTvTorrentRssReader(showName);
	}
	
	public Show getShow()
	{
		Show returnShow;
		
		returnShow = tvrage.getShow();
		Show dailyShow = daily.getShow();
		returnShow.merge(dailyShow);
		
		return returnShow;
	}
	
	
	public boolean updateShow(Show a)
	{
		/*
		 * Right now TvRageXmlReader and EztvRssReader are assigned the responsibility of
		 * updating shows, but this method should do the work.
		 * 
		 *  Reason being is time complexity's 
		 *  	TvRageXmlReader.updateShow() == O(newSeasons.size()^2 * newE.size())
		 *  	EztvRssReader.updateShow() == O(newSeasons.size()^2 * newE.size())
		 *  
		 *  	Making this method == O(newSeasons.size()^4 * newE.size^2) == ouch
		 *  
		 *  These method's only achieve set's and get's so it would be nice to recognize
		 *  a episode has changed in this method and then do all the set's and get's 
		 *  at the same time, cutting the time complexity in half. 
		 */
		boolean showUpdated = false;
		if(a.merge(tvrage.getShow()) || a.merge(daily.getShow()))
		{
			showUpdated = true;
		}
		return showUpdated;
		
	}
}
